<?php
namespace Admin\Controller;
use Think\Controller;
class AnswerController extends CommonController {
	//首页
    public function index()
    {
        $sql = 'select t1.*,t2.username,t3.title from answer t1 inner join user t2 on t1.uid=t2.id inner join question t3 on t1.qid=t3.id where t1.is_del=1';
        $answer = M()->query($sql);
        $this->assign('answer',$answer);

        $this->display();
    }

    //删除状态 为0 
    public function is_del()
    {
        $id = I('post.id');
        $sql = 'update answer set is_del=0 where id='.$id;
        $res = M()->execute($sql);
       if ($res) {
           $arr = array(
                'error' => 0,
                'info' => '回答删除成功'
            );
           echo json_encode($arr);
       }else {
            $arr = array(
                'error' => 1,
                'info' => '回答删除失败'
            );
           echo json_encode($arr);
       }
    }

    //批量删除
    public function deletes()
    {
      //print_r($_POST);exit;
      //Array ( [arr] => Array ( [0] => 1 [1] => 2 ) )
      if (IS_POST) {
        $arr = I('post.arr');
        $ids = implode(",", $arr);

        $res = M('answer')->delete($ids);
          if ($res) {
              $arr = array(
                  'error' =>0,
                  'info'=>"回答删除成功"
                  );
              echo json_encode($arr);
          }else {
              $arr = array(
                  'error' =>1,
                  'info'=>"回答删除失败"
                  );
              echo json_encode($arr);
          }
      }
    }

    //意见反馈页面
    public function feedback()
    {
    	$this->display();
    }
}